<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=PxlRVeTTdUBRH0e8prY7FniKpEaPPS27"></script>
    <style type="text/css">
        .tangram-suggestion-main {
            z-index: 999999;
        }
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";font-size:14px;}
       /* #l-map{height:600px;width:100%;}
        #2-map{height:600px;width:100%;}*/
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <template>
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane label="分布图"  @click="tet1()" name="first">
                        <div id="2-map" style="width: 100%;height: 500px"></div>
                    </el-tab-pane>
                    <el-tab-pane label="详细信息" name="second">
                        <div class="filter-container">
                            <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                            <el-button @click="conditionQuery()" class="dalfBut">查询</el-button>
                            <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                            <el-button @click="exportExcel">导出Excel</el-button>
                        </div>
                        <el-table size="big" current-row-key="id" :data="dataList" stripe highlight-current-row>
                            <el-table-column type="index" align="center" label="序号"></el-table-column>
                            <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                            <el-table-column prop="lon" label="所在经度" align="center"></el-table-column>
                            <el-table-column prop="lat" label="所在纬度" align="center"></el-table-column>
                            <el-table-column label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="pagination-container">
                            <el-pagination
                                    class="pagiantion"
                                    @current-change="handleCurrentChange"
                                    :current-page="pagination.currentPage"
                                    :page-size="pagination.pageSize"
                                    layout="total, prev, pager, next, jumper"
                                    :total="pagination.total">
                            </el-pagination>
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </template>
            <!-- 新增标签弹层 -->
            <div class="add-form">

                <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                    <div slot="footer" class="dialog-footer">
                    <div class="filter-container">
                        <el-input id="suggestId" size="20" placeholder="地址名称" style="width: 500px;" class="filter-item" v-model="add.address" ></el-input>
                        <el-button type="primary" class="butT" @click="handleAdd()">确定添加</el-button>
                        <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;  "></div>
                    </div>
                    <!-- <div id="r-result">请输入:<input type="text" id="suggestId" size="20"  v-model="address"style="width:150px;" /></div>
                     <el-button type="primary" class="butT"  @click="handleAdd()">确定添加</el-button>-->
                    <br>
                    <div id="1-map" style="width: 100%;height: 500px"></div>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>

    var vue = new Vue({
        el: '#app',
        data:{
            activeName:"first",
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            add:{
                address:'',
                lon:'',
                lat:''
            },
            dataList: [],//当前页要展示的分页列表数据
            dialogFormVisible: false,//增加表单是否可见
        },
        //钩子函数，VUE对象初始化完成后自动执行

        created() {
            this.findPage() //调用分页查询方法
        },
        methods: {
            //添加
            handleAdd () {
                axios.post("/address/add.do",this.add).then((res)=>{
                      if (res.data.flag){
                          this.$message({
                              message:res.data.message,
                              type: "success"
                          });
                          this.dialogFormVisible = false;
                      }
                      this.findPage();
                })
            },
            //分页查询
            findPage() {
                var param={
                    "currentPage":this.pagination.currentPage,
                    "pageSize":this.pagination.pageSize,
                    "queryString":this.pagination.queryString
                };
                axios.post("/address/findPage.do",param).then((resp)=>{
                    this.dataList=resp.data.rows;
                    this.pagination.total=resp.data.total;
                    var map2 = new BMap.Map("2-map");
                    map2.centerAndZoom("武汉",12);
                    map2.enableScrollWheelZoom();
                    for (let add of resp.data.rows) {
                        var mkr =new BMap.Marker(new BMap.Point(add.lon,add.lat));
                        var label5 = new BMap.Label(add.address,{offset:new BMap.Size(20,-10)});
                        mkr.setLabel(label5);
                        map2.addOverlay(mkr);
                    }
                });
            },
            //条件查询
            conditionQuery(){
                if (this.pagination.queryString) {
                    this.pagination.currentPage = 1;
                }
                this.findPage();
            },
            // 重置表单
            resetForm() {
                this.add={};
            },
            // 弹出添加窗口
            handleCreate() {
                var _this=this;
                //重置表单数据
                this.resetForm();
                //显示新建窗口
                this.dialogFormVisible = true;
                var map1 = new BMap.Map("1-map");
                map1.centerAndZoom("武汉",12);
                map1.enableScrollWheelZoom();
                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                    {"input" : "suggestId"
                        ,"location" : map1
                    });
                ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
                    var str = "";
                    var _value = e.fromitem.value;
                    var value = "";
                    if (e.fromitem.index > -1) {
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
                    value = "";
                    if (e.toitem.index > -1) {
                        _value = e.toitem.value;
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                    G("searchResultPanel").innerHTML = str;
                });
                var myValue;
                ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
                    var _value = e.item.value;

                    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
                    setPlace();
                });
                function setPlace(){
                    map1.clearOverlays();    //清除地图上所有覆盖物
                    function myFun(){
                        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                        map1.centerAndZoom(pp, 18);
                        map1.addOverlay(new BMap.Marker(pp));
                        _this.add.lon=pp.lng;
                        _this.add.lat=pp.lat;
                    }
                    var local = new BMap.LocalSearch(map1, { //智能搜索
                        onSearchComplete: myFun
                    });
                    _this.add.address=myValue;
                    local.search(myValue);
                }

                // function markerFun (points,label,infoWindows) {
                //     map.addOverlay(label);
                //     label.addEventListener("click",function (event) {
                //         console.log("0001");
                //         map.openInfoWindow(infoWindows,points);//参数：窗口、点  根据点击的点出现对应的窗口
                //     });
                // }
            },
            // 弹出编辑窗口
            handleUpdate(row) {

            },
            //切换页码
            handleCurrentChange(currentPage) {
                //修改当前页码
                this.pagination.currentPage = currentPage;
                //调用查询方法
                this.findPage()
            },
            // 删除
            handleDelete(row) {
                axios.get("/address/delete.do?id="+row.id).then((res)=>{
                    if(res.data.flag){
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        this.findPage();
                    }else {
                        this.$message.error(res.data.message)
                    }
                }).catch(()=>{
                    this.$message.error("删除失败")
                })
            },
            exportExcel(){
                window.location.href = '/address/downAddressExcel.do';
            }
        },
    });
    function G(i) {
      return document.getElementById(i)
    }
</script>
</html>